﻿using System;
using System.IO;
using System.Windows.Media.Imaging;
using System.Drawing;

namespace BeeCoders.Tools.Wpf.FileExplorer
{
	public class FileViewModel : ItemViewModel
	{

	
		public FileViewModel( string fullPath, string name )
		{
			FullPath = fullPath;
			Name = name;

			if (FileExplorerViewModel.Instance.ShowRealIcons)
			{
				Icon icon = Icon.ExtractAssociatedIcon(fullPath);
				if (icon != null)
				{
					// make sure that is it fails, we get the default icon
					try
					{
						Stream stream = new MemoryStream();
						icon.Save(stream);
						BitmapDecoder decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.None);
						BitmapSource src = decoder.Frames[0];
						ImageName = src;

					}
					catch (Exception)
					{

						ImageName = "../Images/files.png";
					}
				}
				
			}
			else
			{
				ImageName = "../Images/files.png";
			}


			HasCheckbox = true;
		}
	}

}
